#include "Queue.h"

void Queue_Init(CircularQueue *q){
    q->head = 0; 
    q->tail = 0;
    q->count = 0;

}

//判断队列是否为空
bool Queue_isEmpty(const CircularQueue *q){
    return (q->count == 0);

}
//判断队列是否为满
bool Queue_isFull(const CircularQueue *q){
    return (q->count == Queue_Capacity);
}

//入队
bool Queue_EnQueue(CircularQueue *q,uint8_t val){
    if(Queue_isFull(q)) return false;
    q->data[q->tail] = val;
    q->tail = (q->tail + 1) % Queue_Capacity;
    q->count++;
    return true;

}
//出队
bool Queue_DeQueue(CircularQueue *q,uint8_t *val){
    if(Queue_isEmpty(q))return false;
    *val = q->data[q->head];
    q->head = (q->head + 1) % Queue_Capacity;
    q->count--;
    return true;
}